#include<iostream>
#include<vector>
using namespace std;
bool check[10];
vector<int> path;
int n = 0, k = 0;
void dfs(int level)
{
    if (level == k)
    {
        for (auto& num : path)
        {
            cout << num << " ";
        }
        cout << endl;
    }

    for (int i = 1; i <= n; i++)
    {
        if (!check[i])
        {
            check[i] = true;
            path.push_back(i);
            dfs(level + 1);
            path.pop_back();
            check[i] = false;
        }

    }
}

int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        check[i] = true;
        path.push_back(i);
        dfs(1);
        path.pop_back();
        check[i] = false;
    }
    return 0;
}